#include <stdio.h>

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    int i, j, ret = 1;
    for (i = n; i > 0; i--)
    {
        ret *= i;
        ret %= m;
    }
    printf("%d\n", ret);
    return 0;
}